package zpe.model;

import java.util.List;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import zpe.genericcrud.model.Entidade;

@Table(name="tb_conteiner",schema="dbo")
@Entity
public class Conteiner implements Entidade {

	private static final long serialVersionUID = 1L;

	@Id
	@Column(name="ci_conteiner")
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Long id;

	@Column(name="nr_numero")
	private Long numero;

	@Column(name="sg_sigla")
	private String sigla;

	@Column(name="nr_digito")
	private Long digito;

	@Column(name="vl_tara")
	private Double tara;

/*	@OneToMany(mappedBy="cliente")
	@Cascade({ CascadeType.ALL })
	private Armador armador;
*/
	@OneToMany(mappedBy="conteiner")
	@Cascade({ CascadeType.ALL })
	private List<Lacre> lacres;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long getNumero() {
		return numero;
	}

	public void setNumero(Long numero) {
		this.numero = numero;
	}

	public String getSigla() {
		return sigla;
	}

	public void setSigla(String sigla) {
		this.sigla = sigla;
	}

	public Long getDigito() {
		return digito;
	}

	public void setDigito(Long digito) {
		this.digito = digito;
	}

	public Double getTara() {
		return tara;
	}

	public void setTara(Double tara) {
		if(tara != null){
			String taraFormadata = tara.toString().replaceAll(",", ".");
			this.tara = Double.parseDouble(taraFormadata);
		}else{
			this.tara = tara;
		}
			
	}
/*
	public Armador getArmador() {
		return armador;
	}

	public void setArmador(Armador armador) {
		this.armador = armador;
	}*/

	public List<Lacre> getLacres() {
		return lacres;
	}

	public void setLacres(List<Lacre> lacres) {
		this.lacres = lacres;
	}

	@Override
	public Map<String, Object> notEmptyFields() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Conteiner other = (Conteiner) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return this.numero + " - " + this.sigla;
	}
}
